| Conditions | 3 |
| Paths | 9 |
| Total Lines | 52 |
| Lines | 52 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | View Code Duplication | import { |
|
| 8 | var route = function(req, res, next){ |
||
| 9 | Hooks.instance.trigger('beforeRoute', req, res, next) |
||
| 10 | if(typeof res._header !== 'undefined' && res._header !== null) return |
||
| 11 | |||
| 12 | var p = new Promise((resolve) => { |
||
| 13 | cmsOperations.save.save( |
||
| 14 | fileUtils.getFilePath(req.body.filePath), |
||
| 15 | req.body.tplPath, |
||
| 16 | req.body.json, |
||
| 17 | '', |
||
| 18 | 'draft', |
||
| 19 | null, |
||
| 20 | 'reject') |
||
| 21 | .then(() => { |
||
| 22 | resolve() |
||
| 23 | }).catch(function(e) { |
||
| 24 | console.error(e) |
||
| 25 | }) |
||
| 26 | }) |
||
| 27 | |||
| 28 | p.then((resSave) => { |
||
| 29 | cmsOperations.save.save( |
||
| 30 | fileUtils.getFilePath(req.body.filePath), |
||
| 31 | req.body.tplPath, |
||
| 32 | req.body.json, |
||
| 33 | '', |
||
| 34 | 'reject', |
||
| 35 | resSave, |
||
| 36 | 'reject') |
||
| 37 | .then((resSave) => { |
||
| 38 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 39 | res.set('Content-Type', 'application/json') |
||
| 40 | res.send(JSON.stringify({error: resSave.error})) |
||
| 41 | } |
||
| 42 | var result |
||
| 43 | if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 44 | result = resSave |
||
| 45 | } |
||
| 46 | if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 47 | result = { |
||
| 48 | success: 1, |
||
| 49 | json: resSave.json |
||
| 50 | } |
||
| 51 | } |
||
| 52 | Manager.instance.updateList() |
||
| 53 | res.set('Content-Type', 'application/json') |
||
| 54 | res.send(JSON.stringify(result)) |
||
| 55 | }) |
||
| 56 | }).catch(function(e) { |
||
| 57 | console.error(e) |
||
| 58 | }) |
||
| 59 | } |
||
| 60 | |||
| 61 | export default route |